﻿@model HomeStayWebCP.Models.BusinessObject.CommentObject
@*<script src="@Url.Content("~/Scripts/jquery-1.8.2.min.js")" type="text/javascript"></script>*@
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
<script src="../../Content/Paging/Pages.js" type="text/javascript"></script>
<link href="../../Content/Paging/Pages.css" rel="stylesheet" type="text/css" />
<style>
    .comment
    {
        padding: 12px;
        width: 630px;
        position: relative;
        background-color: #FCFCFC;
        border: 1px solid #C8C8C8;
        border-radius: 5px;
        font-weight: normal;
        color: #444;
        margin-bottom: 10px;
    }
    .comment:hover
    {
        background-color: white;
    }
    .comment .name
    {
        font-size: 12px;
        padding-bottom: 10px;
        color: #8B9EE7;
    }
    
    .comment .date
    {
        font-size: 10px;
        padding: 6px 0;
        position: absolute;
        right: 15px;
        top: 10px;
        color: #bbb;
    }
    
    .comment p
    {
        font-size: 14px;
        line-height: 1.5;
        overflow-x: hidden;
    }
    
</style>
<script type="text/javascript" language="javascript">
    $(document).ready(function() {
        pages(@ViewBag.page, @ViewBag.page, @ViewBag.count);
    });
</script>
@*List Comment*@
@using (Ajax.BeginForm("InsertComment", "Comments", null, new AjaxOptions()
{
    HttpMethod = "Post",
    //UpdateTargetId = "resultbox",
    UpdateTargetId = "comment",
    OnSuccess = "document.getElementById('Content').value = ''"

}, new { id = "form" }))
{
    @Html.ValidationSummary(true)
    <fieldset style="padding: 0px; border: none">
        @*
              <div class="editor-label">
            @Html.LabelFor(model => model.Content)
        </div> *@
        <div class="editor-field">
            @Html.TextAreaFor(model => model.Content, new { style = "width:650px;height:80px", placeholder = "Leave your comment..." })
            @Html.ValidationMessageFor(model => model.Content)
        </div>
        <p>
            @if (HttpContext.Current.Session["username"] != null)
            {
                <input type="submit" value="Comment" style="float: right; background: #4F6AA2; color: White" />
            }
            else
            {
                <input type="button" value="Comment" style="float: right; background: #4F6AA2; color: White"
                    id="notcomment" />
                
            }
        </p>
    </fieldset>
    <div id="resultbox" style="overflow: auto; width: 680px; height: 500px;" >
        @{
            int i = 0;
            if (ViewContext.Controller.ViewBag.ViewComment != null)
            {
                foreach (var item in ViewContext.Controller.ViewBag.ViewComment)
                {
            <div class="comment">
                <div class="name">@ViewContext.Controller.ViewBag.ViewComment[i].UserName</div>
                <div class="date">@ViewContext.Controller.ViewBag.ViewComment[i].DateComment
                    <a href="/Comments/DeleteComment?commentId=@ViewContext.Controller.ViewBag.ViewComment[i].CommentID" class="deletecomment" style="color: blue;font-size: 14px;">
                        Delete</a>
                </div>
                <p>@Html.Raw(@ViewContext.Controller.ViewBag.ViewComment[i].Content)</p>
            </div>
                    i++;
                }
            }
            else
            {
                foreach (var item in ViewBag.ListComment)
                {
            <div class="comment">
                <div class="name">@ViewBag.ListComment[i].UserName</div>
                <div class="date">
                    @ViewBag.ListComment[i].DateComment
                    <a href="/Comments/DeleteComment?commentId=@ViewBag.ListComment[i].CommentID" class="deletecomment" style="color: blue;font-size: 14px;">
                        Delete</a>
                </div>
                <p>@Html.Raw(@ViewBag.ListComment[i].Content)</p>
            </div>
                    i++;
                }
            }
        }
    </div>
    <div id="load_page">
    </div>
}
<script type="text/javascript">
    $(function () {
        $("#notcomment").click(function () {
            $('a[data-ajax-update="#dialog"]')[0].click();
        });

    });
</script>